Skip to content

Fix ENODATA and unrecognised POSIX errors not treated as disconnections - #64

Merged
Keith-wright merged 1 commit into
mainfrom
fix-enodata-disconnection
Mar 3, 2026
Merged

Keith-wright merged 1 commit into
mainfrom
fix-enodata-disconnection

Conversation

@Keith-wright

Copy link
Copy Markdown
Contributor

Fixes #62

When a WebSocket connection receives POSIX error 96 (ENODATA: "No message available on STREAM"), the previous isDisconnectionNWError check did not recognise it, leaving the NWConnection in a zombie .ready state. Subsequent reconnect attempts would reuse the dead connection and immediately fail with the same error, causing an unrecoverable reconnection loop.

Changes

  • Add a catch-all else if case .posix(_) branch to isDisconnectionNWError to handle ENODATA and any other unrecognised POSIX errors that also indicate a dead connection
  • Call connection?.cancel() before scheduling disconnection reporting to ensure the zombie NWConnection is torn down so a fresh one is created on reconnect
  • Bump version to 0.5.10

Thanks to @joelmbell for the suggestion in #63.

@joelmbell joelmbell left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@aonemd aonemd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@aonemd aonemd added release Preparing for a new release and removed release Preparing for a new release labels Mar 3, 2026
@Keith-wright
Keith-wright merged commit 69e3e44 into main Mar 3, 2026
4 checks passed
@Keith-wright
Keith-wright deleted the fix-enodata-disconnection branch March 3, 2026 16:55
adhorodyski added a commit to callstack-internal/Expensify-App that referenced this pull request Aug 14, 2026
We ship NWWebSocket 0.5.7 with two bugs, both fixed upstream, and both
matching what our iOS clients do in production:

- A reconnect that can never succeed - pusher/NWWebSocket#59, in 0.5.8.
- Dead sockets that report themselves .ready - pusher/NWWebSocket#62, fixed
  in pusher/NWWebSocket#64, in 0.5.10.

PusherSwift 10.1.6 already asks for NWWebSocket '~> 0.5.7', so only
Podfile.lock was holding us at 0.5.7. Pinning the floor in the Podfile picks
both fixes up with no other movement. 0.5.7..0.5.10 touches one file and
changes no public API, so PusherSwift 10.1.6 links against it unchanged.
OldDot shares this pod via PusherSwiftWithEncryption, so it gets both fixes
too. Android is untouched.

Where it hits us. 1d query on start=2026-08-09T00:00:00Z
end=2026-08-10T00:00:00Z, deduplicated on (email, client timestamp):

  DISCONNECTED -> RECONNECTING   142,924 / 21,793 users = 6.56   100% iOS
  RECONNECTING -> DISCONNECTED    88,464 / 20,409 users = 4.34   100% iOS
  CONNECTING   -> DISCONNECTED    75,672 / 19,881 users = 3.81   100% iOS
  RECONNECTING -> CONNECTED       25,708 / 11,327 users = 2.27   90.4% iOS
  Socket presumed dead (iOS)      48,954 / 21,811 users = 2.24

Only 18.0% of retries reach CONNECTED - 4.6 failures per success - and
60.6% of active iOS users entered the loop that day.

Expect ReconnectApp to rise, not fall: a failed retry never re-subscribes,
so fixing the loop converts 88,464 silent failures into successful connects.

Why not bump @pusher/pusher-websocket-react-native to 1.3.5, which was the
previous approach here. The wrapper's 1.3.1..1.3.3 diff contains no source
files at all, only a podspec re-pin, and PusherSwift 10.1.6..10.1.10 changes
no socket code either - both fixes are in NWWebSocket and nowhere else. What
the bump does add is PusherSwift 10.1.9's swap of TweetNacl for
PusherTweetNacl, a fork of the same C library. PusherSwiftWithEncryption was
never published past 10.1.6, so OldDot stays on TweetNacl and both forks
collide in the HybridApp binary. Dropped for a pin that carries the fixes and
builds.

Also fixes a dead branch in our own error plumbing. Native passed
{data: {message}} with no `type`, while PusherConnectionManager gates its
error handler on `'type' in error`, so every native Pusher error was dropped
before any log call - 0 of 63,271 error lines carried a native user agent.
Routing them through WEB_SOCKET_ERROR makes the reconnect cause
attributable, which is what lets this change be measured rather than assumed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
adhorodyski added a commit to callstack-internal/Expensify-App that referenced this pull request Aug 14, 2026
We ship NWWebSocket 0.5.7 with two bugs, both fixed upstream, and both
matching what our iOS clients do in production:

- A reconnect that can never succeed - pusher/NWWebSocket#59, in 0.5.8.
- Dead sockets that report themselves .ready - pusher/NWWebSocket#62, fixed
  in pusher/NWWebSocket#64, in 0.5.10.

PusherSwift 10.1.6 already asks for NWWebSocket '~> 0.5.7', so only
Podfile.lock was holding us at 0.5.7. Pinning the floor in the Podfile picks
both fixes up with no other movement. 0.5.7..0.5.10 touches one file and
changes no public API, so PusherSwift 10.1.6 links against it unchanged.
OldDot shares this pod via PusherSwiftWithEncryption, so it gets both fixes
too. Android is untouched.

Where it hits us. 1d query on start=2026-08-09T00:00:00Z
end=2026-08-10T00:00:00Z, deduplicated on (email, client timestamp):

  DISCONNECTED -> RECONNECTING   142,924 / 21,793 users = 6.56   100% iOS
  RECONNECTING -> DISCONNECTED    88,464 / 20,409 users = 4.34   100% iOS
  CONNECTING   -> DISCONNECTED    75,672 / 19,881 users = 3.81   100% iOS
  RECONNECTING -> CONNECTED       25,708 / 11,327 users = 2.27   90.4% iOS
  Socket presumed dead (iOS)      48,954 / 21,811 users = 2.24

Only 18.0% of retries reach CONNECTED - 4.6 failures per success - and
60.6% of active iOS users entered the loop that day.

Expect ReconnectApp to rise, not fall: a failed retry never re-subscribes,
so fixing the loop converts 88,464 silent failures into successful connects.

Why not bump @pusher/pusher-websocket-react-native to 1.3.5, which was the
previous approach here. The wrapper's 1.3.1..1.3.3 diff contains no source
files at all, only a podspec re-pin, and PusherSwift 10.1.6..10.1.10 changes
no socket code either - both fixes are in NWWebSocket and nowhere else. What
the bump does add is PusherSwift 10.1.9's swap of TweetNacl for
PusherTweetNacl, a fork of the same C library. PusherSwiftWithEncryption was
never published past 10.1.6, so OldDot stays on TweetNacl and both forks
collide in the HybridApp binary. Dropped for a pin that carries the fixes and
builds.

Also fixes a dead branch in our own error plumbing. Native passed
{data: {message}} with no `type`, while PusherConnectionManager gates its
error handler on `'type' in error`, so every native Pusher error was dropped
before any log call - 0 of 63,271 error lines carried a native user agent.
Routing them through WEB_SOCKET_ERROR makes the reconnect cause
attributable, which is what lets this change be measured rather than assumed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENODATA isn't treated as a disconnection error and can cause a misleading "ready" state

4 participants